package VO

import "eag_arch_layout/internal/model"

// ClmFilter 栏位过滤器
type ClmFilter struct {
	Title string `json:"title"`
	Prop  string `json:"prop"`
	Opt   string `json:"opt"`
	Val   string `json:"val"`
}

// PageSearchVxeModel VxeTable分页的请求
type PageSearchVxeModel struct {
	Limit       int `json:"limit"`
	Offset      int `json:"offset"`
	PageIndex   int `json:"pageIndex"`
	Sort        string
	Order       string
	searchParam map[string]string
	clmFilters  []*ClmFilter
}

func (m *PageSearchVxeModel) GetSearchParam() map[string]string {
	return m.searchParam
}

func (m *PageSearchVxeModel) GetClmFilters() []*ClmFilter {
	return m.clmFilters
}

// NewPageSearchVxeModel 构造VXE模型函数
func NewPageSearchVxeModel(size uint32, page uint32, sort string, order string, para map[string]string, filters []*ClmFilter) *PageSearchVxeModel {
	searchModel := &PageSearchVxeModel{}
	if size > 0 {
		searchModel.Limit = int(size)
	} else {
		searchModel.Limit = model.DEFAULT_PAGE_SIZE
	}
	if page > 1 {
		searchModel.PageIndex = int(page)
	} else {
		searchModel.PageIndex = 1
	}
	searchModel.Offset = (searchModel.PageIndex - 1) * searchModel.Limit
	searchModel.Sort = sort
	searchModel.Order = order

	searchModel.searchParam = para
	searchModel.clmFilters = filters
	return searchModel
}
